// pages/chartere_bus6/category_chartere6/category_chartere6.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    date:'请选择当地用车时间',
    wineshop:{id:0,name:"请选择送达地点/酒店"},
    airport: { id: 0, airportName:'请选择送机场'},
    goodsList:[],
    bannerList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHot();
    this.getBanner();
  }, linkList: function (e) {
    var goodsType = e.target.dataset.type;
    if (goodsType == undefined) {
      return;
    }
    wx.navigateTo({
      url: '../travel/travel?type=' + goodsType
    })
  }, getBanner: function () {
    var that = this;
    httpUtil.getHttp("/banner/get?bannerType=1", {}, function (res) {
      that.setData({
        bannerList: res
      })
    })
  },
  getHot:function(){
    var that = this;
    httpUtil.getHttp("/goods_travel/hot?type=6", {}, function (res) {
      that.setData({
        goodsList: res
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },  //获取轮播图
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  searchCar:function(){
    var that=this;

    if (that.data.airport.id == 0) {
      wx.showToast({
        title: '请选择机场',
        icon: 'loading',
        duration: 1000,
        mask: true
      })
      return;
    }
    if (that.data.wineshop.id == 0) {
      wx.showToast({
        title: '请选择送达酒店',
        icon: 'loading',
        duration: 1000,
        mask: true
      })
      return;
    }
    if (that.data.date == '请选择当地用车时间'  ) {
      wx.showToast({
        title: '请选择用车时间',
        icon: 'loading',
        duration: 1000,
        mask: true
      })
      return;
    }
    
    wx.navigateTo({
      url: '../search_models/search_models'
    })
  },
  selJc:function(){
    wx.navigateTo({
      url: '../select_airport/select_airport'
    })
  },
  selHetol:function(){
    var that=this;
    if (that.data.airport.id==0){
      wx.showToast({
        title: '请选择机场',
        icon: 'loading',
        duration: 1000,
        mask: true
      })
      return;
    }
    wx.navigateTo({
      url: '../choose_hotel/choose_hotel'
    })
  },
  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  showDetail:function(e){
    var that=this;
    var id=e.target.dataset.id;

    var type = e.target.dataset.type;

    if(id==''||id==undefined){
      return;
    }
    if (that.data.date == '请选择当地用车时间') {
      wx.showToast({
        title: '请选择用车时间',
        icon: 'loading',
        duration: 1000,
        mask: true
      })
      return;
    }

 
    httpUtil.getHttp("/goods_travel/get/" + id + "/" + type + "/specification", {}, function (res) {
      var shoppingList = [];
      var userInfo = util.getKey("userInfo");
      if (res == null || res.length==0)
      {
        wx.showToast({
          title: '商品规格无效',
          icon: 'loading',
          duration: 1000,
          mask: true
        })
        return;
      }
      shoppingList.push({ "num": 1, "specificationId": res[0].id, "goodsId": res[0].goodsId, "userId": userInfo.id, "del_status": 0, "date": that.data.date })
      httpUtil.postHttp("/order/addShoppingList", { list: shoppingList }, function (res) {

        wx.navigateTo({
          url: '../reserve1/reserve1?id=' + res[0].id
        });

      });

    })
  
  },
  changeDate(e) {
    this.setData({ date: e.detail.value });
  }, address:function(){

  }, address:function(){
        var that=this;
        if (that.data.date == '请选择当地用车时间') {
            wx.showToast({
                title: '请选择用车时间',
                icon: 'loading',
                duration: 1000,
                mask: true
            })
            return;
        }
        wx.navigateTo({
            url: '../line_car/line_car'
        })
    }
})